Skip to content

Fix pagination bug #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

rian-dolphin
Copy link

@rian-dolphin rian-dolphin commented Jun 27, 2025

Related to #865 #868 and #886. I noticed it when using list_ticker_news and this change fixed it for my news use case.

This implementation should retain the current behaviour unless the user explicitly passes a limit, in which case it is respected. It will paginate until the limit is satisfied.

@rian-dolphin rian-dolphin requested a review from a user June 27, 2025 15:26
@justinpolygon
Copy link
Contributor

Hey @rian-dolphin, thanks again for submitting the PR and highlighting this across multiple issues. After reviewing the broader set of use cases (including your list_ticker_news example), as discussed we decided to take a slightly different approach by adding a top-level pagination flag to the RESTClient. This allows users to explicitly disable auto-pagination when needed, while keeping the default behavior unchanged.

With pagination=True (the default), the client continues to fetch all pages, treating limit as the page size. If you set pagination=False, the client stops after the first page and enforces limit as a strict cap on the number of results.

Here’s how it works with your use case:

from polygon import RESTClient

client = RESTClient(trace=True, pagination=False)

news = []
for item in client.list_ticker_news("AAPL", limit=3):
    news.append(item)

print(news)

This will return exactly 3 results — no extra pages fetched. The fix is available in v1.15.0, just run pip install -U polygon-api-client� to get the latest release, and we’ve updated the README with more details on how this flag works.

Thanks again for the nudge to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants